{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Typesetting Math in your book\n",
    "\n",
    "Jupyter Book uses [MathJax](http://docs.mathjax.org/) for typesetting math in your\n",
    "book. This allows you to have LaTeX-style mathematics in your online content.\n",
    "This page shows you a few ways to control this.\n",
    "\n",
    "For more information about equation numbering, see the\n",
    "[MathJax equation numbering documentation](http://docs.mathjax.org/en/v2.7-latest/tex.html#automatic-equation-numbering).\n",
    "\n",
    "# In-line math\n",
    "\n",
    "To insert in-line math use the `$` symbol within a Markdown cell.\n",
    "For example, the text `$this_{is}^{inline}$` will produce: $this_{is}^{inline}$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Math blocks\n",
    "\n",
    "You can also include math blocks for separate equations. This allows you to focus attention\n",
    "on more complex or longer equations, as well as link to them in your pages. To use a block\n",
    "equation, wrap the equation in either `$$` or `\\begin` statements.\n",
    "\n",
    "For example,\n",
    "\n",
    "```bash\n",
    "\\begin{equation}\n",
    "  \\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "\\end{equation}\n",
    "```\n",
    "results in\n",
    "\n",
    "\\begin{equation}\n",
    "  \\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "\\end{equation}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and\n",
    "\n",
    "```bash\n",
    "$$\n",
    "  \\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "$$\n",
    "```\n",
    "\n",
    "results in\n",
    "\n",
    "$$\n",
    "  \\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Numbering equations\n",
    "\n",
    "MathJax has built-in support for numbering equations. This makes it possible to\n",
    "easily reference equations throughout your page. To do so, add this tag\n",
    "to a block equation:\n",
    "\n",
    "`\\tag{<number>}`\n",
    "\n",
    "The `\\tag` provides a number for the equation that will be inserted when you refer\n",
    "to it in the text.\n",
    "\n",
    "For example, the following code:\n",
    "\n",
    "```bash\n",
    "equation 1\n",
    "$$\n",
    "  \\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "  \\tag{1}\n",
    "$$\n",
    "\n",
    "equation 2\n",
    "\n",
    "$$\n",
    "  \\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "  \\tag{2}\n",
    "$$\n",
    "\n",
    "equation 999\n",
    "\n",
    "$$\n",
    "  \\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "  \\tag{999}\n",
    "$$\n",
    "```\n",
    "\n",
    "Results in these math blocks:\n",
    "\n",
    "equation 1\n",
    "$$\n",
    "  \\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "  \\tag{1}\n",
    "$$\n",
    "\n",
    "equation 2\n",
    "\n",
    "$$\n",
    "  \\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "  \\tag{2}\n",
    "$$\n",
    "\n",
    "equation 999\n",
    "\n",
    "$$\n",
    "  \\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "  \\tag{999}\n",
    "$$\n",
    "\n",
    "### Automatic numbering\n",
    "\n",
    "If you'd like **all** block equations to be numbered with MathJax, you can activate\n",
    "this with the following configuration in your `_config.yml` file:\n",
    "\n",
    "```yaml\n",
    "number_equations: true\n",
    "```\n",
    "\n",
    "In this case, all equations will have numbers. If you'd like to deactivate\n",
    "an equation's number, include a `\\notag` with your equation, like so:\n",
    "\n",
    "```bash\n",
    "$$\n",
    "  \\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "  \\notag\n",
    "$$\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Linking to equations\n",
    "\n",
    "Adding `\\label{mylabel}` to an equation allows you to refer to the equation elsewhere in the page. You\n",
    "can define a human-friendly label and MathJax will insert an anchor with the following form:\n",
    "\n",
    "```html\n",
    "#mjx-eqn-mylabel\n",
    "```\n",
    "\n",
    "If you use `\\label` in conjunction with `\\tag`, then you can insert references directly to an equation\n",
    "by using the `\\ref` syntax. For example, here's an equation with a tag and label:\n",
    "\n",
    "```bash\n",
    "$$\n",
    "\\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "\\label{mylabel1}\\tag{24}\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "\\label{mylabel2}\\tag{25}\n",
    "$$\n",
    "```\n",
    "\n",
    "$$\n",
    "\\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "\\label{mylabel1}\\tag{24}\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\int_0^\\infty \\frac{x^3}{e^x-1}\\,dx = \\frac{\\pi^4}{15}\n",
    "\\label{mylabel2}\\tag{25}\n",
    "$$\n",
    "\n",
    "Now, we can refer to these math blocks with `\\ref` elements. For example,\n",
    "we can mention Equation \\ref{mylabel1} using `\\ref{mylabel1}` and\n",
    "Equation \\ref{mylabel2} with `\\ref{mylabel2}`.\n",
    "\n",
    "Note that these equations also have anchors on them, which can be used to link\n",
    "to an equation from elsewhere, for example with this link text:\n",
    "\n",
    "```html\n",
    "<a href=\"#mjx-eqn-mylabel2\">My link</a>\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
